eightfandomcom-20200222-history
How To Shrink VirtualBox Windows 8 VDI File
If you are using dynamically allocated storage as your virtual hard disk type, the file size will gradually grow as you continue to use Windows 8. Unfortunately even after deleting files on Windows 8, the VDI file will not change due to disk fragmentation, and data that is located at the end of the disk block. There are 3 basic steps to take to shrink your Windows 8 VDI file. #chkdsk /f #defrag the drive #sdelete -z Defragment the Hard Drive Before you actually attempt the shrinking operation, you will need to defragment the disk blocks so that all empty blocks will be moved towards the end of the disk. Please read this Wikipedia article for more information on Disk Defragmentation. The Disk Defragmenter in Windows 8 do not contain a visible user interface. You will need to run Disk Defragmenter from an Administrator command prompt. You will want to run Disk Defragmenter with the following flags: /U Print the progress of the operation on the screen. /V Print verbose output containing the fragmentation statistics. /X Perform free space consolidation on the specified volumes. C:\Windows\system32>defrag C: /U /H /X Microsoft Drive Optimizer Copyright © 2011 Microsoft Corp. Invoking defragmentation on (C:)... Analysis: 100% complete. Pre-Optimization Report: Volume Information: Volume size = 24.65 GB Free space = 13.76 GB Total fragmented space = 0% Largest free space size = 11.63 GB Note: File fragments larger than 64MB are not included in the fragmentat ion statistics. Performing pass 1: Defragmentation: 100% complete. Free Space Consolidation: 100% complete. Performing pass 2: Eviction: 100% complete. Defragmentation: 100% complete. Free Space Consolidation: 100% complete. Performing pass 3: Eviction: 100% complete. Defragmentation: 100% complete. Free Space Consolidation: 100% complete. Performing pass 4: Eviction: 100% complete. Free Space Consolidation: 100% complete. Performing pass 5: Eviction: 100% complete. Free Space Consolidation: 100% complete. Performing pass 6: Free Space Consolidation: 100% complete. Performing pass 7: Defragmentation: 100% complete. Free Space Consolidation: 100% complete. Performing pass 8: Defragmentation: 100% complete. Free Space Consolidation: 100% complete. Performing pass 9: Defragmentation: 100% complete. Free Space Consolidation: 100% complete. Performing pass 10: Free Space Consolidation: 100% complete. Performing pass 11: Free Space Consolidation: 100% complete. The operation completed successfully. Post Defragmentation Report: Volume Information: Volume size = 24.65 GB Free space = 13.76 GB Total fragmented space = 0% Largest free space size = 11.63 GB Note: File fragments larger than 64MB are not included in the fragmentat ion statistics. Zapping Free Space Next, you will need to use sdelete to zero out the free space completely before the optimization. You can get a copy of sdelete here . Start the Windows command prompt as an Administrator, then run this command: C:\Windows\system32>sdelete -z SDelete - Secure Delete v1.6 Copyright © 1999-2010 Mark Russinovich Sysinternals - www.sysinternals.com SDelete is set for 1 pass. Free space cleaned on C:\ 1 drives zapped Compacting the VDI File Shut down your virtual machine and have it fully stopped before you compact the VDI file, otherwise you may encounter errors or even worse corruption of your virtual machine. Finally, you will need to use the VBoxManage command in VirtualBox, with the compact flag. For example, in Windows you should run this: C:\>"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyhd C:\ Users\username\Virtual_Machines\Windows 8\Windows8.vdi --compact 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%